package com.yowasa.xiuxian.engine.battle.strategy.drop.all;

import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.BuffContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@BS(name = "无羁的朱赤之蝶")
@Order(502)
@Component
public class WuJiZhiDie extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return null;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        BuffContent checkBuff = first.getBuff().get("朱赤之火");
        int value = 0;
        if(checkBuff != null && (checkBuff.getDuration() !=0 || checkBuff.getNum()!=0)){
            //存在buff，进行引爆
            double a = 0.4;
            if(first.getBattleInfo().getChp() < first.getBattleInfo().getHp()*0.4){
                a = 0.6;
            }
            int dmg = (int) ((first.getBattleInfo().getHp() - first.getBattleInfo().getChp()) * a);
            battleHelper.autoAction(this, first, second, content, dmg, "无羁的朱赤之蝶");
            value = (int) (dmg * 0.5);
        }
        //伤害计算完毕，烧血，重置buff，回血
//        first.getBattleInfo().setChp((int) (first.getBattleInfo().getChp() - first.getBattleInfo().getHp() * 0.2));
        first.getBattleInfo().setChp((int) (first.getBattleInfo().getChp() * 0.7));
        //buff
        BuffContent buffContent = new BuffContent();
        buffContent.setDuration(10);
        buffContent.setNum(1);
        first.getBuff().put("朱赤之火", buffContent);
        first.getCd().put("无羁的朱赤之蝶", 3);
        //回血
        first.getBattleInfo().setChp(first.getBattleInfo().getChp() + value);
        content.getMsgLog().add(first.getUserBO().getName()+"燃烧了30%的血量，并因无羁的朱赤之蝶回复了"+value+"点生命值");

    }

    @Override
    public void limit(UserBO user) {
        throw new HandlerException("该战技无法直接学习，需要拥有 武器-[护摩之杖] ，装备在身上时自动学会");

    }

    @Override
    public String limitDesc() {
        return "学习/使用无羁的朱赤之蝶需要拥有 武器-[护摩之杖] ";
    }

    @Override
    public String desc() {
        return "以炽焰洗净一切不洁之物，让污秽与火光一同升向可容纳一切的高天\n以自己的鲜血为引，让对方燃起朱赤之火，燃烧自己当前血量的30%，为对方挂上印记\n" +
                "再次释放时将引爆印记，造成当前已损失血量40%的伤害，并回复本次伤害值50%的血量\n当血量低于40%时，伤害值倍率将变为60%，cd 3回合\n无羁的朱赤之蝶造成的伤害无物理或法术属性，但会触发防御策略，但回复值以原伤害计算，不触发治疗倍率";
    }
    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        Integer cd = user.getCd().get("无羁的朱赤之蝶");
        if (cd != null && cd > 0) {
            return false;
        }
//        int costHp = user.getBattleInfo().getHp() / 5;
//        if (user.getBattleInfo().getChp() < costHp) {
//            return false;
//        }
        return true;
    }
}
